package com.sthz.facepay.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.sthz.facepay.model.Card;

public class CardSqlProvider {

    public String insertSelective(Card record) {
        BEGIN();
        INSERT_INTO("st_card");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getItid() != null) {
            VALUES("itid", "#{itid,jdbcType=INTEGER}");
        }
        
        if (record.getTitle() != null) {
            VALUES("title", "#{title,jdbcType=VARCHAR}");
        }
        
        if (record.getLogo() != null) {
            VALUES("logo", "#{logo,jdbcType=VARCHAR}");
        }
        
        if (record.getColour() != null) {
            VALUES("colour", "#{colour,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getValue() != null) {
            VALUES("value", "#{value,jdbcType=VARCHAR}");
        }
        
        if (record.getGrant_number() != null) {
            VALUES("grant_number", "#{grant_number,jdbcType=INTEGER}");
        }
        
        if (record.getUser_limitation() != null) {
            VALUES("user_limitation", "#{user_limitation,jdbcType=INTEGER}");
        }
        
        if (record.getExplain() != null) {
            VALUES("explain", "#{explain,jdbcType=VARCHAR}");
        }
        
        if (record.getMin_consume_money() != null) {
            VALUES("min_consume_money", "#{min_consume_money,jdbcType=DOUBLE}");
        }
        
        if (record.getEffective_start_time() != null) {
            VALUES("effective_start_time", "#{effective_start_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getEffective_end_time() != null) {
            VALUES("effective_end_time", "#{effective_end_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getActivity_effective_start_time() != null) {
            VALUES("activity_effective_start_time", "#{activity_effective_start_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getActivity_effective_end_time() != null) {
            VALUES("activity_effective_end_time", "#{activity_effective_end_time,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Card record) {
        BEGIN();
        UPDATE("st_card");
        
        if (record.getItid() != null) {
            SET("itid = #{itid,jdbcType=INTEGER}");
        }
        
        if (record.getTitle() != null) {
            SET("title = #{title,jdbcType=VARCHAR}");
        }
        
        if (record.getLogo() != null) {
            SET("logo = #{logo,jdbcType=VARCHAR}");
        }
        
        if (record.getColour() != null) {
            SET("colour = #{colour,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getValue() != null) {
            SET("value = #{value,jdbcType=VARCHAR}");
        }
        
        if (record.getGrant_number() != null) {
            SET("grant_number = #{grant_number,jdbcType=INTEGER}");
        }
        
        if (record.getUser_limitation() != null) {
            SET("user_limitation = #{user_limitation,jdbcType=INTEGER}");
        }
        
        if (record.getExplain() != null) {
            SET("explain = #{explain,jdbcType=VARCHAR}");
        }
        
        if (record.getMin_consume_money() != null) {
            SET("min_consume_money = #{min_consume_money,jdbcType=DOUBLE}");
        }
        
        if (record.getEffective_start_time() != null) {
            SET("effective_start_time = #{effective_start_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getEffective_end_time() != null) {
            SET("effective_end_time = #{effective_end_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getActivity_effective_start_time() != null) {
            SET("activity_effective_start_time = #{activity_effective_start_time,jdbcType=TIMESTAMP}");
        }
        
        if (record.getActivity_effective_end_time() != null) {
            SET("activity_effective_end_time = #{activity_effective_end_time,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}